package com.atguigu;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SaveMode;
import org.apache.spark.sql.SparkSession;

/**
 * @author yhm
 * @create 2022-12-26 10:41
 */
public class Test07_Parquet {
    public static void main(String[] args) {
        // 1. 创建sparkConf配置对象
        SparkConf conf = new SparkConf().setAppName("sql").setMaster("local[*]");

        // 2. 创建sparkSession连接对象
        SparkSession spark = SparkSession.builder().config(conf).getOrCreate();

        // 3. 编写代码
        Dataset<Row> rowDataset = spark.read().json("input/user.json");


        rowDataset.write()
                .mode(SaveMode.Overwrite)
                .parquet("output");

        // 读取parquet文件
        Dataset<Row> output = spark.read().parquet("output");
        output.printSchema();
        output.show();

        // 4. 关闭sparkSession
        spark.close();
    }
}
